<?php

/**
 * This is the model class for table "{{property}}".
 *
 * The followings are the available columns in table '{{property}}':
 * @property integer $id
 * @property string $address
 * @property string $suburb
 * @property string $postcode
 * @property string $state
 * @property string $country
 * @property string $status
 * @property string $Note
 * @property integer $customerId
 *
 * The followings are the available model relations:
 * @property Customer $customer
 */
class Property extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Property the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{property}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('address, suburb, postcode, state, country, customerId', 'required'),
			array('customerId', 'numerical', 'integerOnly'=>true),
			array('address, suburb, postcode, state, country, status', 'length', 'max'=>255),
			array('Note', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, address, suburb, postcode, state, country, status, Note, customerId', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'customer' => array(self::BELONGS_TO, 'Customer', 'customerId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'address' => 'Address',
			'suburb' => 'Suburb',
			'postcode' => 'Postcode',
			'state' => 'State',
			'country' => 'Country',
			'status' => 'Status',
			'Note' => 'Note',
			'customerId' => 'Customer',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('suburb',$this->suburb,true);
		$criteria->compare('postcode',$this->postcode,true);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('country',$this->country,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('Note',$this->Note,true);
		$criteria->compare('customerId',$this->customerId);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}